﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YRevitJig;

namespace YArchitech.HVAC
{
	internal class DimEquipmentJig : XUiJigBase
	{
		public DimEquipmentJig(UIDocument uDoc, DimEquipmentData eD) : base(uDoc)
		{
			this.uiDoc = uDoc;
			this.equData = eD;
		}

		public bool SelEquipment()
		{
			bool result;
			try
			{
				this.refEpui = this.uiDoc.Selection.PickObject((Autodesk.Revit.UI.Selection.ObjectType)1, new DimEquipmentFilter(), "请选择要标注的设备...");
				result = true;
			}
			catch
			{
				result = false;
			}
			return result;
		}

		public bool DimPoint()
		{
			bool result;
			try
			{
				this.PointDim = this.uiDoc.Selection.PickPoint("请选择要标注的位置...");
				result = true;
			}
			catch
			{
				result = false;
			}
			return result;
		}

		public override void Draw(PaintEventArgs paintEventArgs)
		{
			base.Draw(paintEventArgs);
			System.Drawing.Point ptCur = this.m_ptCur;
			if (this.m_ptCur.IsEmpty || paintEventArgs == null)
			{
				return;
			}
			if (this.refEpui == null)
			{
				return;
			}
			try
			{
				XYZ globalPoint = this.refEpui.GlobalPoint;
				XYZ xyz = base.Client2Revit(this.m_ptCur);
				XGraphics g = new XGraphics(paintEventArgs.Graphics, base.JigPen);
				if (this.equData != null && this.equData.IsLead)
				{
					XYZ xyz2 = XYZ.BasisX;
					if (xyz.X < globalPoint.X)
					{
						xyz2 = -1.0 * XYZ.BasisX;
					}
					xyz += 1.0 * xyz2;
					new XLine2D(this.m_ptCur, base.Revit2Client(globalPoint)).Draw(g);
					new XLine2D(this.m_ptCur, base.Revit2Client(xyz)).Draw(g);
				}
			}
			catch (Exception ex)
			{
				ex.ToString();
				throw ex;
			}
		}

		public XYZ PointDim = XYZ.Zero;

		public Reference refEpui;

		private UIDocument uiDoc;

		private DimEquipmentData equData;
	}
}
